<?php
/**
 * 错误页面
 *
 * @author maomao.thx@gmail.com
 * @copyright Copyright (c) 2009 Green Shore (http://www.iwgame.com)
 * @version $Id: ErrorController.php 1097 2011-12-16 01:34:59Z maomao.thx@gmail.com $
 */
class ErrorController extends Zend_Controller_Action
{

    public function errorAction()
    {
        $this->_helper->layout()->disableLayout();
        $errors = $this->_getParam('error_handler');

        if (!$errors) {
            $this->view->message = 'You have reached the error page';
            return;
        }

        switch ($errors->type) {
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:

                // 404 error -- controller or action not found
                $this->getResponse()->setHttpResponseCode(404);
                $this->view->message = 'Page not found';
                break;
            default:
                // application error
                $this->getResponse()->setHttpResponseCode(500);
                $this->view->message = 'Application error';

                // Log exception, if logger available
                IG_Log::log()->crit($errors->exception->getMessage(), array(
                    'code' => $errors->exception->getCode(),
                    'line' => $errors->exception->getLine(),
                    'file' => $errors->exception->getFile(),
                    'trace' => $errors->exception->getTraceAsString(),
                ));
                break;
        }

        // conditionally display exceptions
        if ($this->getInvokeArg('displayExceptions') == true) {
            $this->view->exception = $errors->exception;
        }

        $this->view->request   = $errors->request;
    }
}

